package com.tomecode.rvr.generator.filter;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * File filter for files and dirs which will be ignored
 * 
 * @author Frastia Tomas
 * 
 */
public final class IgnorFilter implements FileFilter {

	/**
	 * list of {@link FileNamePropertyFilter} which will be ignored
	 */
	private final List<FileNamePropertyFilter> ignoredFilesFilter;

	/**
	 * list of {@link DirNamePropertyFilter} which will be ignored
	 */
	private final List<DirNamePropertyFilter> ignoredDirsFilter;

	/**
	 * Construktor
	 * 
	 * @param ignoredFiles
	 *            list of files which will be ignored
	 * @param ignoredDirs
	 *            list of dirs which will be ignored
	 */
	public IgnorFilter(String[] ignoredFiles, String[] ignoredDirs) {
		ignoredFilesFilter = new ArrayList<FileNamePropertyFilter>();
		ignoredDirsFilter = new ArrayList<DirNamePropertyFilter>();
		for (String ignoredFile : ignoredFiles) {
			ignoredFilesFilter.add(new FileNamePropertyFilter(ignoredFile));
		}
		for (String ignoredDir : ignoredDirs) {
			ignoredDirsFilter.add(new DirNamePropertyFilter(ignoredDir));
		}
	}

	public final boolean accept(File pathname) {
		for (FileNamePropertyFilter filterProperty : ignoredFilesFilter) {
			if (filterProperty.matche(pathname)) {
				return false;
			}
		}

		for (DirNamePropertyFilter filterProperty : ignoredDirsFilter) {
			if (filterProperty.matche(pathname)) {
				return false;
			}
		}
		return true;
	}

}
